using System;
using System.Data.Objects;

namespace ZhiHeng.Consume.DataContract
{
    [Serializable]
    public class SearchParameter
    {
        public SearchParameter()
        {
        }

        public SearchParameter(ObjectParameter objectParameter)
        {
            this.Name = objectParameter.Name;
            this.Value = objectParameter.Value.ToString();
            this.ParameterType = objectParameter.ParameterType.FullName;
        }

        public SearchParameter(string name, object value)
        {
            this.Name = name;
            this.Value = value.ToString();
            this.ParameterType = value.GetType().FullName;
        }

        public string Name { set; get; }

        public string ParameterType { get; set; }

        public string Value { get; set; }

        public ObjectParameter GetObjectParameter()
        {
            var obj = System.Convert.ChangeType(this.Value, Type.GetType(this.ParameterType));
            var param = new ObjectParameter(this.Name, obj);
            return param;
        }
    }
}